package org.testfire.realm.model.entities.testfire;

import javax.persistence.*;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: granum
 * Date: Sep 9, 2007
 * Time: 12:50:22 PM
 */
@Entity
@Table(catalog = "testfire", name = "agent")
public class AgentEntity
{
	private Integer id;
	private String name;
	private String host;
	private String description;
	private Integer user;
	private Boolean allownonusertests;
	private List<TestRunnerQueueEntity> queues;
    private Integer lastping;
    private Long lastPingTime;
	private TestsetEntity hastestset;
	private List<TestsetResultEntity> testsetResults;

	@OneToMany(mappedBy = "agent")
	public List<TestsetResultEntity> getTestsetResults()
	{
		return testsetResults;
	}

	public void setTestsetResults(List<TestsetResultEntity> testsetResults)
	{
		this.testsetResults = testsetResults;
	}

	@ManyToOne
	@JoinColumn(name = "hastestset", referencedColumnName = "id")
	public TestsetEntity getHastestset()
	{
		return hastestset;
	}

	public void setHastestset(TestsetEntity hastestset)
	{
		this.hastestset = hastestset;
	}

	@Basic
    @Column(name = "lastpingtime", nullable = false, length = 20)
    public Long getLastPingTime() {
        return lastPingTime;
    }

    public void setLastPingTime(Long isbusy) {
        this.lastPingTime= isbusy;
    }

    @Basic
    @Column(name = "lastping", nullable = false, length = 11)
    public Integer getLastping() {
        return lastping;
    }

    public void setLastping(Integer lastping) {
        this.lastping = lastping;
    }

    @ManyToMany(mappedBy = "agents", cascade = CascadeType.REFRESH )
	public List<TestRunnerQueueEntity> getQueues()
	{
		return queues;
	}

	public void setQueues(List<TestRunnerQueueEntity> queues)
	{
		this.queues = queues;
	}

	@Basic
	@Column(name = "allowNonUserTests", nullable = false, length = 1)
	public Boolean getAllownonusertests()
	{
		return allownonusertests;
	}

	public void setAllownonusertests(Boolean allownonusertests)
	{
		this.allownonusertests = allownonusertests;
	}

	@Basic
	@Column(name = "user", length = 10)
	public Integer getUser()
	{
		return user;
	}

	public void setUser(Integer user)
	{
		this.user = user;
	}

	@Basic
	@Column(name = "description", length = 65535)
	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	@Basic
	@Column(name = "host", nullable = false)
	public String getHost()
	{
		return host;
	}

	public void setHost(String host)
	{
		this.host = host;
	}

	@Basic
	@Column(name = "name", nullable = false)
	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	@Id
	@Column(name = "id", nullable = false, length = 10)
	public Integer getId()
	{
		return id;
	}

	public void setId(Integer id)
	{
		this.id = id;
	}

	@Transient
	public boolean isEqual(AgentEntity that){
		return this.id.equals(that.id);
	}
}
